const express = require('express')
const bodyParser=require('body-parser')
const cookieParser=require('cookie-parser')
const userRouter = require('./user')

const app = express()
//work with express
const server=require('http').Server(app)
const io= require('socket.io')(server)

app.use(cookieParser())
app.use(bodyParser.json())
app.use('/user', userRouter)

io.on('connection',function(socket){
    console.log('user login')
    socket.on('sendmsg',function(data){
        console.log(data)
        io.emit('recvmsg',data)
    })
})

app.get('/', function (req, res) {
    res.send('<h1>hello</h1>')
})

// app.get('/', function (req, res) {     res.send('<h1>Hello world</h1>') })
// app.get('/data', function (req, res) {     User         .find({}, function
// (err, doc) {             res.json(doc)         })
// //res.json({name:'imooc',type:'IT'}) })

server.listen(9093, function () {
    console.log('这是9093端口')
})